package com.yanqu.road.server.cmd.kowloon;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.kowloon.KowloonProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.kowloon.KowloonModule;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_KOWLOON_GET_USER_DATA, desc = "获取用户数据")
public class KowloonGetUserDataCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        KowloonProto.KowloonUserDataReqMsg req = KowloonProto.KowloonUserDataReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(KowloonModule.class).getUserDataByCmd();
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            KowloonProto.KowloonUserDataRespMsg.Builder respMsg = KowloonProto.KowloonUserDataRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_KOWLOON_GET_USER_DATA, respMsg);
        }
    }
}
